package com.qfedu.controller;

import com.qfedu.fmmall.service.ProductCommentsService;
import com.qfedu.fmmall.service.ProductService;
import com.qfedu.fmmall.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

@RestController
@CrossOrigin
@RequestMapping("/product")
@Api(tags = "商品管理",value = "提供商品数据所需的接口")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    private ProductCommentsService productCommentsService;

    @ApiOperation("商品基本数据")
    @GetMapping("/detail-info/{pid}")
    public ResultVo getProductDetail(@PathVariable String pid){
        return productService.getProductBatisInfo(pid);
    }

    @ApiOperation("获取商品的参数数据")
    @GetMapping("/detail-params/{pid}")
    public ResultVo getProductParams(@PathVariable String pid){
        return  productService.getProductBatisPrams(pid);
    }

    @ApiOperation("获取商品的评论数据")
    @GetMapping("/detail-comments/{pid}")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int",name = "pageNum",value="当前页码",required = true),
            @ApiImplicitParam(dataType = "int",name="limit",value = "页面显示长度",required = true)
    })
    public ResultVo getProductCommens(@PathVariable String pid,
                                       int pageNum,
                                       int limit){
        return  productCommentsService.CommontsByProductId(pid,pageNum,limit);
    }

    @ApiOperation("获取商品的好中差评数量数据")
    @GetMapping("/detail-comments-count/{pid}")
    public ResultVo getProductCommentsCountParams(@PathVariable String pid){
        return  productCommentsService.getCommontsCountByProductId(pid);
    }

    @ApiOperation("获取商品三级分类下的数据")
    @GetMapping("/listbycid/{cid}")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int",name="cid",value = "三级分类的id",required = true),
            @ApiImplicitParam(dataType = "int",name = "pageNum",value="当前页码",required = true),
            @ApiImplicitParam(dataType = "int",name="limit",value = "页面显示长度",required = true)
    })
    public ResultVo getProductByCategoryId(@PathVariable("cid")int cid,int pageNum,int limit){
        return productService.getProductByCategoryId(cid,pageNum,limit);
    }

    @ApiOperation("获取商品三级分类下的品牌数据")
    @GetMapping("/listbrand/{cid}")
    public ResultVo getBrandList(@PathVariable("cid")int cid){
        return  productService.getBrandList(cid);
    }
    @ApiOperation("查询商品")
    @GetMapping("/searchProduct")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String",name="keyword",value = "要查询的字符",required = true),
            @ApiImplicitParam(dataType = "int",name = "pageNum",value="当前页码",required = true),
            @ApiImplicitParam(dataType = "int",name="limit",value = "页面显示长度",required = true)
    })
    public ResultVo schearProduct(String keyword,int pageNum,int limit){
        return productService.searchProductName(keyword,pageNum,limit);
    }
    @ApiOperation("根据商品的关键字查询商品品牌")
    @GetMapping("/searchBrand")
    @ApiImplicitParam(dataType = "String",name="keyword",value = "要查询的字符",required = true)
    public ResultVo searchBrandByKeyword(String keyword){
        return  productService.searchBrand(keyword);
    }




}

